<?php
/**
 *
 * @package 
 * @since 1.0
 */
 
class SystemAction extends Action{
	/**
	 * ------------------------------
	 * 预处理
	 * ------------------------------
	 */
	function _initialize(){
		if( !isset($_SESSION['adm_name']) or !isset($_SESSION['isAdmin']) ) $this->redirect('Index/login');
	}
	/**
	 * ------------------------------
	 * 系统基本设置
	 * ------------------------------
	 */
	function sysset(){	
		$list = M('sysconfig')->order('id asc')->select();
		foreach($list as $k=>$v){
		   $data[$v['varname']] = $v['value'];
		}
		$this->assign('pagetitle','系统基本参数设置');
		$this->assign($data);
		$this->display();
	}
	
	function setsys(){
		if (!M()->autoCheckToken($_POST)){
			$this->error('非法操作');
			die();
		}
		unset($_POST['__hash__']);
		foreach ($_POST as $k=>$v) {
			$data['value'] = $v;
			M('sysconfig')->where("varname='".$k."'")->save($data);
		}
	
		$this->success("已保存！");
	}
	







	
	/**
	 * ------------------------------
	 * 图片广告位管理
	 * ------------------------------
	 */

	function jiaodian(){
	
		import("@.ORG.Page");
		$count	= M('guanggaowei')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('guanggaowei')->order('id asc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '图片广告位列表');
	
		$this->display();
	 }
	
	function editjiaodian(){
        $id = intval($_GET['id']);
		if($id==''){
		     $this->assign('pagetitle', '添加图片广告位');
		}else{
			 $list = M('guanggaowei')->find($id);
			 $this->assign($list);
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改图片广告位');
		}
		$this->display('jiaodian_edit');
	}
   
   function dojiaodian(){
	   
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		
		
		if($_POST['id']){
				if( M('guanggaowei')->save($_POST) ){
					$this->assign('jumpUrl', U('System/jiaodian'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('guanggaowei')->add($_POST) ){
					$this->assign('jumpUrl', U('System/jiaodian'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function deljiaodian(){
	    $ids = $_POST['ids'];
		$del = M('guanggaowei')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}
	/**
	 * ------------------------------
	 * 友情链接
	 * ------------------------------
	 */
	function youlian(){
	
		import("@.ORG.Page");
		$count	= M('youlian')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('youlian')->order('xu asc,id asc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '友情链接列表');
	
		$this->display();
	 }
	
	function edityoulian(){
        $id = intval($_GET['id']);
		if($id==''){
		     $this->assign('pagetitle', '添加友情链接');
		}else{
			 $list = M('youlian')->find($id);
			 $this->assign($list);
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改友情链接');
		}
		$this->display('youlian_edit');
	}
   
   function doyoulian(){
	   
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		
		
		if($_POST['id']){
				if( M('youlian')->save($_POST) ){
					$this->assign('jumpUrl', U('System/youlian'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('youlian')->add($_POST) ){
					$this->assign('jumpUrl', U('System/youlian'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function delyoulian(){
	    $ids = $_POST['ids'];
		$del = M('youlian')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}
    /**
	 * ------------------------------
	 * 网站说明
	 * ------------------------------
	 */
	function wzsm(){
	
		import("@.ORG.Page");
		$count	= M('wzsm')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('wzsm')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '网站说明');
	
		$this->display();
	 }
	
	function editwzsm(){
        $id = intval($_GET['id']);
		if($id==''){
		     $this->assign('pagetitle', '网站说明');
		}else{
			
			 $list = M('wzsm')->find($id);
				foreach($list as $k=>$v){
				 if(get_magic_quotes_gpc()!='-1' || get_magic_quotes_gpc()==true){
					$list[$k]=stripslashes($v); 
				 } 
				}
			 $this->assign($list);
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改 网站说明');
		}
		$this->display('wzsm_edit');
	}
   
   function dowzsm(){
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		if($_POST['id']){
				if( M('wzsm')->save($_POST) ){
					$this->assign('jumpUrl', U('System/wzsm'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('wzsm')->add($_POST) ){
					$this->assign('jumpUrl', U('System/wzsm'));
					$this->success('修改成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function delwzsm(){
	    $ids = $_POST['ids'];
		$del = M('wzsm')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}
	 
	/**
	 * ------------------------------
	 * 表情管理
	 * ------------------------------
	 */

	function biaoqing(){
	
		import("@.ORG.Page");
		$count	= M('biaoqing')->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		$list = M('biaoqing')->order('xu asc,id desc')->limit($Page->firstRow.','.$Page->listRows)
						     ->select();
	    $this->assign('list', $list);
		$this->assign('page', $show);
		$this->assign('pagetitle', '图片广告位列表');
	
		$this->display();
	 }
	
	function editbiaoqing(){
        $id = intval($_GET['id']);
		if($id==''){
		     $this->assign('pagetitle', '添加图片广告位');
		}else{
			 $list = M('biaoqing')->find($id);
			 $this->assign($list);
			 $this->assign('type', 'edit');
			 $this->assign('pagetitle', '修改图片广告位');
		}
		$this->display('biaoqing_edit');
	}
   
   function dobiaoqing(){
	   
   	    header("Content-Type:text/html; charset=utf-8");
		if( !M()->autoCheckToken($_POST) ) $this->error('禁止站外提交！');
		unset($_POST['__hash__']);
		foreach ($_POST as $k => $v) {
			if($v == '') unset($_POST[$k]);
		}
		
		
		if($_POST['id']){
				if( M('biaoqing')->save($_POST) ){
					$this->assign('jumpUrl', U('System/biaoqing'));
					$this->success('修改成功！');
				}else{
					$this->error('没有任何改动　或　修改失败！');
				}
		}else{
		      if( M('biaoqing')->add($_POST) ){
					$this->assign('jumpUrl', U('System/biaoqing'));
					$this->success('添加成功！');
			  }else{
					$this->error('添加失败！');
			  }
		}
	}
	
	function delbiaoqing(){
	    $ids = $_POST['ids'];
		$del = M('biaoqing')->where("id IN ($ids)")->delete();
        echo $del?'1':'0';
	}
 
}